﻿using System;
using System.Windows.Forms;
using System.Collections.Generic;
using Interfaces.General_Interfaces;
using Interfaces.Information_Interfaces;
using Interfaces.Add_Interfaces;
using Model.Domain_Model;
using Repository;
using Presenters.Inherited_Presenters;

namespace Presenters.General_Presenters
{
    public class SearchClientPresenter:OperationStatus
    {
        ISearchClientView view = null;
        public IRoadAddView roadView = null;
        public Client selectedClient = null;
        IDb database = Repo.GetDatabaseInstance();

        public SearchClientPresenter(ISearchClientView view)
        {
            this.view = view;
        }

        public void ExitApp()
        {
            view.Close();
        }

        public void Search()
        {
            nameOperation = "Wyszukaj klienta";
            try
            {
                view.clientList = database.Clients.SearchClient(nameClient: view.nameClient, surnameClient: view.surnameClient, inventedName: view.inventedName, nameCorp: view.nameCorporation);
            }
            catch (Exception ex)
            {
                exception = ex.Message;
                view.ShowError();
            }
        }

        public void Choose()
        {
            if (selectedClient != null)
            {
                roadView.SetParams(selectedClient);
                view.Close();
            }
        }
    }
}
